﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _2017._02._09.Employee
{
    class Program
    {
        static void Main(string[] args)
        {
            List<Employee> employers = new List<Employee>(5);
            employers.Add(new Worker());
            employers.Add(new Worker());
            employers.Add(new Worker());
            employers.Add(new HourlyWorker());
            employers.Add(new HourlyWorker());

            foreach (var employee in employers)
            {
                employee.CalculateSalary();
                Console.WriteLine();
            }

            Console.ReadKey();
        }
    }

    abstract class Employee
    {
        public string Name { get; private set; }

        public Employee()
        {
            Console.WriteLine("Enter name:");
            string name = Console.ReadLine();
            if (String.IsNullOrWhiteSpace(name))
                throw new ArgumentException();
            Name = name;
        }

        public abstract void CalculateSalary();
    }

    class Worker: Employee
    {
        private int yearSalary;
        public int YearSalary
        {
            get { return yearSalary; }
            private set
            {
                if (value < 0)
                    throw new ArgumentException();
                yearSalary = value;
            }
        }

        public Worker()
        {
            Console.WriteLine("Enter year salary:");
            yearSalary = Int32.Parse(Console.ReadLine());
            YearSalary = yearSalary;
        }

        public override void CalculateSalary()
        {
            double salary = YearSalary / 12;
            Console.WriteLine("Name: {0} Salary: {1}", Name, salary);
        }
    }

    class HourlyWorker: Employee
    {
        private double rate;
        private double hours;
        public double Rate
        {
            get { return rate; }
            private set
            {
                if (value < 0)
                    throw new ArgumentException();
                rate = value;
            }
        }
        
        public double Hours
        {
            get { return hours; }
            private set
            {
                if (value < 0)
                    throw new ArgumentException();
                hours = value;
            }
        }

        public HourlyWorker()
        {
            Console.WriteLine("Enter rate:");
            rate = Int32.Parse(Console.ReadLine());
            Rate = rate;
            Console.WriteLine("Enter hours:");
            hours = Int32.Parse(Console.ReadLine());
            Hours = hours;
        }

        public override void CalculateSalary()
        {
            double salary = Rate * Hours;
            Console.WriteLine("Name: {0} Salary: {1}", Name, salary);
        }
    }


}
